﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Elderos.Highlight.Search;

namespace Elderos.Highlight
{
    public class ComplexResult : RuleResult
    {
        private readonly List<IRuleResult> _incomingResults; 

        public ComplexResult(string[] rulenames, IEnumerable<IRuleResult> incomingResults) : base(rulenames)
        {
            _incomingResults = new List<IRuleResult>(incomingResults);
        }

        public override IEnumerable<FactorValue> GetFactorValues()
        {
            var factorValues = new List<FactorValue>();
            
            for (int i = 0; i < _incomingResults.Count(); i++)
            {
                IRuleResult incomingResult = _incomingResults[i];
                var factors = new List<FactorValue>(incomingResult.GetFactorValues());
                for (int k = 0; k < factors.Count; k++)
                {
                    var factor = factors[k];
                    factorValues.Add(new FactorValue(RuleNames[i] + "_" + factor.FactorName, factor.Weight));
                }
            }

            return factorValues;
        }
    }
}
